/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelMantenimiento.java
 *
 * Created on 28-dic-2011, 12:08:46
 */
package incidencias;

import accesoBD.QueryTecnico;
import idiomas.messages;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;

/**
 * Clase que muestra el rol del Técnico
 * @author Juan Antonio Cobo Zamora
 */
public class PanelMantenimiento extends javax.swing.JFrame {

    private int id_parte;
    private int[] arrayid_incidencia;
    private int id_incidencia;
    private int id_actuacion;
    private Mantenimiento mant;

    /**
     * Constructor del panel
     * @param q Objeto QueryTecnico utilizado para hacer las consultas realizadas por el Técnico
     */
    public PanelMantenimiento(QueryTecnico q) {
        mant = new Mantenimiento(q);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        IncidenciasBoxModel = new DefaultComboBoxModel();
        PartesComboBox = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        ParteTextField = new javax.swing.JTextArea();
        ParteLabel = new javax.swing.JLabel();
        CerrarParteButton = new javax.swing.JButton();
        rechazarButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        RechazoTextField = new javax.swing.JTextArea();
        lenguageLabel = new javax.swing.JLabel();
        lenguageSelect = new javax.swing.JComboBox();
        RecargarButton = new javax.swing.JButton();
        id_parteLabel = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        listModel = new DefaultListModel();
        listaIncid = new javax.swing.JList();
        jScrollPane4 = new javax.swing.JScrollPane();
        actuacionText = new javax.swing.JTextArea();
        incLabel = new javax.swing.JLabel();
        actuacionLabel = new javax.swing.JLabel();
        crearIncidenciaButton = new javax.swing.JButton();
        incidenciaTextField = new javax.swing.JTextField();
        tInvertidoTextField = new javax.swing.JTextField();
        costeTextField = new javax.swing.JTextField();
        tEstimadoLabel = new javax.swing.JLabel();
        costeLabel = new javax.swing.JLabel();
        tInvertidoLabel = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        salirButton = new javax.swing.JButton();
        tEstimadoTextField = new javax.swing.JTextField();
        crearActuacionButton = new javax.swing.JButton();
        actFinalizada = new javax.swing.JCheckBox();
        actualizarActuacionButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        PartesComboBox.setModel(IncidenciasBoxModel);
        PartesComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PartesComboBoxActionPerformed(evt);
            }
        });

        ParteTextField.setEditable(false);
        ParteTextField.setLineWrap(true);
        ParteTextField.setRows(5);
        ParteTextField.setWrapStyleWord(true);
        ParteTextField.setAutoscrolls(false);
        ParteTextField.setMaximumSize(new java.awt.Dimension(240, 240));
        ParteTextField.setRequestFocusEnabled(false);
        jScrollPane1.setViewportView(ParteTextField);

        ParteLabel.setText("Parte No ");

        CerrarParteButton.setText("Cerrar Parte");
        CerrarParteButton.setPreferredSize(new java.awt.Dimension(100, 40));
        CerrarParteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CerrarParteButtonActionPerformed(evt);
            }
        });

        rechazarButton.setText("Rechazar Parte");
        rechazarButton.setPreferredSize(new java.awt.Dimension(100, 40));
        rechazarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rechazarButtonActionPerformed(evt);
            }
        });

        RechazoTextField.setColumns(15);
        RechazoTextField.setLineWrap(true);
        RechazoTextField.setRows(5);
        RechazoTextField.setTabSize(5);
        RechazoTextField.setText("Motivos por los que rechazo el parte");
        RechazoTextField.setWrapStyleWord(true);
        RechazoTextField.setMinimumSize(new java.awt.Dimension(0, 0));
        jScrollPane2.setViewportView(RechazoTextField);

        lenguageLabel.setText("Idioma");

        lenguageSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Español", "English" }));
        lenguageSelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lenguageSelectActionPerformed(evt);
            }
        });

        RecargarButton.setText("Recargar Partes");
        RecargarButton.setPreferredSize(new java.awt.Dimension(100, 40));
        RecargarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RecargarButtonActionPerformed(evt);
            }
        });

        listaIncid.setModel(listModel);
        listaIncid.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listaIncidValueChanged(evt);
            }
        });
        jScrollPane3.setViewportView(listaIncid);

        actuacionText.setColumns(20);
        actuacionText.setLineWrap(true);
        actuacionText.setRows(5);
        actuacionText.setWrapStyleWord(true);
        jScrollPane4.setViewportView(actuacionText);

        incLabel.setText("Incidencias");

        actuacionLabel.setText("Actuación");

        crearIncidenciaButton.setText("Crear Incidencia");
        crearIncidenciaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                crearIncidenciaButtonActionPerformed(evt);
            }
        });

        incidenciaTextField.setColumns(10);
        incidenciaTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                incidenciaTextFieldActionPerformed(evt);
            }
        });

        tInvertidoTextField.setColumns(5);
        tInvertidoTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tInvertidoTextFieldActionPerformed(evt);
            }
        });

        costeTextField.setColumns(5);
        costeTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                costeTextFieldActionPerformed(evt);
            }
        });

        tEstimadoLabel.setText("Tiempo Estimado");

        costeLabel.setText("Coste");

        tInvertidoLabel.setText("Tiempo Invertido");

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/incidencias/masterlogo.png"))); // NOI18N

        salirButton.setFont(new java.awt.Font("Tahoma", 0, 18));
        salirButton.setText("SALIR");
        salirButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salirButtonActionPerformed(evt);
            }
        });

        tEstimadoTextField.setColumns(5);
        tEstimadoTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tEstimadoTextFieldActionPerformed(evt);
            }
        });

        crearActuacionButton.setText("Crear Actuación");
        crearActuacionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                crearActuacionButtonActionPerformed(evt);
            }
        });

        actFinalizada.setText("Actuación Finalizada");

        actualizarActuacionButton.setText("Actualizar Actuación");
        actualizarActuacionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actualizarActuacionButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 207, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                .add(layout.createSequentialGroup()
                                    .add(48, 48, 48)
                                    .add(id_parteLabel))
                                .add(PartesComboBox, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(lenguageLabel)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(lenguageSelect, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(ParteLabel)
                            .add(CerrarParteButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(103, 103, 103)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(6, 6, 6)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(incLabel)
                                    .add(layout.createSequentialGroup()
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 143, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(layout.createSequentialGroup()
                                                .add(10, 10, 10)
                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                                    .add(layout.createSequentialGroup()
                                                        .add(10, 10, 10)
                                                        .add(incidenciaTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                                    .add(crearIncidenciaButton))))
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(actuacionLabel)
                                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                                .add(salirButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 135, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(28, 28, 28)
                                                .add(jLabel4))
                                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                                .add(rechazarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 116, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(layout.createSequentialGroup()
                                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                                        .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 206, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                        .add(layout.createSequentialGroup()
                                                            .add(34, 34, 34)
                                                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                                                .add(layout.createSequentialGroup()
                                                                    .add(tEstimadoLabel)
                                                                    .add(18, 18, 18)
                                                                    .add(tEstimadoTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                                                        .add(costeLabel)
                                                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                                        .add(costeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                                                        .add(tInvertidoLabel)
                                                                        .add(18, 18, 18)
                                                                        .add(tInvertidoTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                                                    .add(layout.createSequentialGroup()
                                                                        .add(4, 4, 4)
                                                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                                                            .add(actFinalizada)
                                                                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                                                                .add(org.jdesktop.layout.GroupLayout.TRAILING, actualizarActuacionButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                                                .add(org.jdesktop.layout.GroupLayout.TRAILING, crearActuacionButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))))
                                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 228, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))))
                            .add(RecargarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 186, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .add(22, 22, 22))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(layout.createSequentialGroup()
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(lenguageLabel)
                                .add(lenguageSelect, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(18, 18, 18)
                            .add(PartesComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(15, 15, 15)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(id_parteLabel)
                                .add(ParteLabel)))
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(incLabel)
                            .add(actuacionLabel)))
                    .add(layout.createSequentialGroup()
                        .add(45, 45, 45)
                        .add(RecargarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(6, 6, 6)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
                        .add(9, 9, 9)
                        .add(rechazarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 79, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                            .add(layout.createSequentialGroup()
                                .add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(crearIncidenciaButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(incidenciaTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(tEstimadoLabel)
                                    .add(tEstimadoTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(9, 9, 9)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(tInvertidoTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(tInvertidoLabel))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(costeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(costeLabel))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(actFinalizada)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(crearActuacionButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(actualizarActuacionButton)
                                .add(9, 9, 9)))
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(33, 33, 33)
                                .add(salirButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 67, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(CerrarParteButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(18, 18, 18))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Controlador que carga las Incidencias asignadas a un parte en listaIncid.
     * Además crea una array donde se guarda el id de cada una de las incidencias
     * que tiene un parte
     * @param evt
     */
private void PartesComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PartesComboBoxActionPerformed


    String descripcionParte = "";

    try {
        id_parte = Integer.parseInt(IncidenciasBoxModel.getSelectedItem().toString());
        id_parteLabel.setText(IncidenciasBoxModel.getSelectedItem().toString());
        descripcionParte = Mantenimiento.descripcionParte(id_parte);
        ParteTextField.setText(descripcionParte);
        listModel.removeListDataListener(PartesComboBox);
        listModel.clear();
        ResultSet rset = Mantenimiento.diagnosticoParte(id_parte);
        rset.last();
        arrayid_incidencia = new int[rset.getRow()];

        rset.beforeFirst();
        int i = 0;
        while (rset.next()) {

            listModel.addElement(rset.getString(2));
            arrayid_incidencia[i] = rset.getInt(1);
            i++;
        }
        listaIncid.setSelectedIndex(-1);
        listModel.addListDataListener(PartesComboBox);
    } catch (SQLException ex) {
        Logger.getLogger(PanelMantenimiento.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_PartesComboBoxActionPerformed
    /**
     * Controlador encargado del botón CerrarParteButton
     * En caso de pulsarlo, se cierra el parte que está seleccionado en
     * PartesComboBox.
     * @param evt 
     */
private void CerrarParteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CerrarParteButtonActionPerformed
    System.err.println(id_parte);
    try {
        Mantenimiento.CerrarParte(id_parte);
    } catch (SQLException ex) {
        Logger.getLogger(PanelMantenimiento.class.getName()).log(Level.SEVERE, null, ex);
    }

}//GEN-LAST:event_CerrarParteButtonActionPerformed
    /**
     * Controlador encargado del botón rechazarButton
     * Rechaza un parte determinado y envía los motivos del rechazo.
     * @param evt 
     */
private void rechazarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rechazarButtonActionPerformed


    String rechazo = RechazoTextField.getText();
    try {
        Mantenimiento.rechazarParte(id_parte, id_actuacion, rechazo);
    } catch (SQLException ex) {
        Logger.getLogger(PanelMantenimiento.class.getName()).log(Level.SEVERE, null, ex);
    }

}//GEN-LAST:event_rechazarButtonActionPerformed
    /**
     * Controlador encargado de cambiar el lenguaje del panel
     * @param evt 
     */
    private void lenguageSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lenguageSelectActionPerformed
        // TODO add your handling code here:
        String Idioma = (String) lenguageSelect.getSelectedItem();
        switch (lenguageSelect.getSelectedIndex()) {
            case 0: //Español
                Idioma = "ES";
                break;
            case 1: //Ingles
                Idioma = "EN";
                break;
        }
        Locale locale = new Locale(Idioma);
        messages.setLocale(locale);
        lenguageLabel.setText(messages.getString("Language"));
        ParteLabel.setText(messages.getString("PartNo"));
        incLabel.setText(messages.getString("Incidences"));
        actuacionLabel.setText(messages.getString("Performance"));
        RechazoTextField.setText(messages.getString("IncidencesIfThereAreAnyone"));
        CerrarParteButton.setText(messages.getString("ClosePart"));
        rechazarButton.setText(messages.getString("RejectPart"));
        RecargarButton.setText(messages.getString("RechargeParts"));
        crearActuacionButton.setText(messages.getString("CreatePerformance"));
        actualizarActuacionButton.setText(messages.getString("UpdatePerformance"));
        salirButton.setText(messages.getString("Exit"));
        crearIncidenciaButton.setText(messages.getString("CreateIncidence"));
        tEstimadoLabel.setText(messages.getString("EstimatedTime"));
        tInvertidoLabel.setText(messages.getString("TimeSpent"));
        costeLabel.setText(messages.getString("Cost"));
        actFinalizada.setText(messages.getString("CompletePerformance"));


    }//GEN-LAST:event_lenguageSelectActionPerformed
    /**
     * Controlador encargado del botón RecargarButton
     * Actualiza los partes asignados a una persona de mantenimiento y los muestra
     * en PartesComboBox. Además, limpia todos los campos del panel
     * @param evt 
     */
private void RecargarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RecargarButtonActionPerformed

    IncidenciasBoxModel.removeListDataListener(PartesComboBox);
    IncidenciasBoxModel.removeAllElements();

    listModel.removeListDataListener(PartesComboBox);
    actuacionText.setText("");
    listModel.clear();
    tEstimadoTextField.setText("");
    tInvertidoTextField.setText("");
    costeTextField.setText("");
    actFinalizada.setSelected(false);

    ParteTextField.setText("");
    RechazoTextField.setText(messages.getString("IncidencesIfThereAreAnyone"));

    try {
        ResultSet rset = Mantenimiento.partesAsignados();
        while (rset.next()) {
            IncidenciasBoxModel.addElement(rset.getInt(1));
        }
        IncidenciasBoxModel.addListDataListener(PartesComboBox);
        listModel.addListDataListener(PartesComboBox);

    } catch (SQLException ex) {
        Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_RecargarButtonActionPerformed
    /**
     * Controlador encargado de actualizar la actuación correspondiente a una incidencia.
     * Se lanza cuando se selecciona uno de los elementos de listaIncid.
     * Habilita o desabilita los botos en función de los parámetros recibidos
     * @param evt 
     */
private void listaIncidValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listaIncidValueChanged

    if (listaIncid.getSelectedIndex() >= 0) {
        try {
            id_incidencia = arrayid_incidencia[listaIncid.getSelectedIndex()];
            id_actuacion = Mantenimiento.getActuaciondeIncidencia(id_incidencia);

            if (id_actuacion != -1) {

                ResultSet rset = Mantenimiento.getActuacion(String.valueOf(id_actuacion));
                while (rset.next()) {
                    tEstimadoTextField.setText(rset.getString(2));
                    tInvertidoTextField.setText(rset.getString(3));
                    costeTextField.setText(rset.getString(6));
                    actuacionText.setText(rset.getString(7));
                    crearActuacionButton.setEnabled(false);
                    actualizarActuacionButton.setEnabled(true);
                    if (!"".equals(tInvertidoTextField.getText())) {
                        actFinalizada.setSelected(true);
                    } else {
                        actFinalizada.setSelected(false);
                    }

                }
            } else {
                tEstimadoTextField.setText("");
                tInvertidoTextField.setText("");
                costeTextField.setText("");
                actuacionText.setText("");
                actFinalizada.setSelected(false);
                crearActuacionButton.setEnabled(true);
                actualizarActuacionButton.setEnabled(false);

            }
        } catch (SQLException ex) {
            Logger.getLogger(PanelMantenimiento.class.getName()).log(Level.SEVERE, null, ex);
        }


    }


}//GEN-LAST:event_listaIncidValueChanged
    /**
     * Controlador encargado del botón crearIncidenciaButton.
     * Crea una nueva incidencia asociada a un parte.
     * @param evt 
     */
private void crearIncidenciaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_crearIncidenciaButtonActionPerformed
    if (!"".equals(incidenciaTextField.getText())) {
        listaIncid.setSelectedIndex(-1);


        String incidencia = incidenciaTextField.getText();

        try {
            Mantenimiento.crearIncidencia(id_parte, incidencia);
            listModel.removeListDataListener(PartesComboBox);
            listModel.clear();
            ResultSet rset = Mantenimiento.diagnosticoParte(id_parte);
            rset.last();
            arrayid_incidencia = new int[rset.getRow()];
            System.out.println(rset.getRow());
            rset.beforeFirst();
            int i = 0;
            while (rset.next()) {

                listModel.addElement(rset.getString(2));
                arrayid_incidencia[i] = rset.getInt(1);
                i++;
            }
            listaIncid.setSelectedIndex(-1);

        } catch (SQLException ex) {
            Logger.getLogger(PanelMantenimiento.class.getName()).log(Level.SEVERE, null, ex);
        }
        listModel.addListDataListener(PartesComboBox);
    }

}//GEN-LAST:event_crearIncidenciaButtonActionPerformed
    /**
     * 
     * @param evt 
     */
private void incidenciaTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_incidenciaTextFieldActionPerformed
}//GEN-LAST:event_incidenciaTextFieldActionPerformed
    /**
     * 
     * @param evt 
     */
private void tInvertidoTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tInvertidoTextFieldActionPerformed
}//GEN-LAST:event_tInvertidoTextFieldActionPerformed
    /**
     * 
     * @param evt 
     */
private void costeTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_costeTextFieldActionPerformed
}//GEN-LAST:event_costeTextFieldActionPerformed
    /**
     * Controlador encargado del botón salirButton, el cuál hace un logOut de 
     * la sesión y nos devuelve a la pantalla de login.
     * 
     * @param evt 
     */
private void salirButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salirButtonActionPerformed

    this.setVisible(false);
    login.main(null);
}//GEN-LAST:event_salirButtonActionPerformed
    /**
     * 
     * @param evt 
     */
private void tEstimadoTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tEstimadoTextFieldActionPerformed
}//GEN-LAST:event_tEstimadoTextFieldActionPerformed
    /**
     * Controlador encargado del botón crearActuación.
     * Crea una nueva actuación para la incidencia seleccionada en la listaIncid
     * @param evt 
     */
private void crearActuacionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_crearActuacionButtonActionPerformed
    String actuacion = actuacionText.getText();
    String t_invertido = tInvertidoTextField.getText();
    String t_estimado = tEstimadoTextField.getText();
    String coste = costeTextField.getText();
    try {
        Mantenimiento.añadirActuacion(String.valueOf(id_incidencia), t_estimado, t_invertido, actuacion, coste);
    } catch (SQLException ex) {
        Logger.getLogger(PanelMantenimiento.class.getName()).log(Level.SEVERE, null, ex);
    }


}//GEN-LAST:event_crearActuacionButtonActionPerformed
    /**
     * Controlador encargado del botón actualizarActuación.
     * Actualiza los datos de la actuación que corresponde con la Incidencia seleccionada
     * en la listaIncid
     * @param evt 
     */
private void actualizarActuacionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actualizarActuacionButtonActionPerformed

    String actuacion = actuacionText.getText();
    String t_invertido = tInvertidoTextField.getText();
    String t_estimado = tEstimadoTextField.getText();
    String coste = costeTextField.getText();
    try {
        Mantenimiento.actualizarActuacion(String.valueOf(id_actuacion), t_estimado, t_invertido, actuacion, coste);
    } catch (SQLException ex) {
        Logger.getLogger(PanelMantenimiento.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_actualizarActuacionButtonActionPerformed

    /**
     * Procedimiento sustituto del main que carga el panel
     * @param args
     * @param query objeto QueryTecnico para que lo pueda utilizar 
     * la clase Mantenimiento para hacer las consultas
     */
    public static void main(String args[], final QueryTecnico query) throws SQLException {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
        
         * 
         * 
         */


        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PanelMantenimiento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PanelMantenimiento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PanelMantenimiento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PanelMantenimiento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                PanelMantenimiento panelMant = new PanelMantenimiento(query);
                panelMant.setVisible(true);
                panelMant.setResizable(false);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CerrarParteButton;
    private javax.swing.JLabel ParteLabel;
    private javax.swing.JTextArea ParteTextField;
    private javax.swing.JComboBox PartesComboBox;
    private javax.swing.JButton RecargarButton;
    private javax.swing.JTextArea RechazoTextField;
    private javax.swing.JCheckBox actFinalizada;
    private javax.swing.JLabel actuacionLabel;
    private javax.swing.JTextArea actuacionText;
    private javax.swing.JButton actualizarActuacionButton;
    private javax.swing.JLabel costeLabel;
    private javax.swing.JTextField costeTextField;
    private javax.swing.JButton crearActuacionButton;
    private javax.swing.JButton crearIncidenciaButton;
    private javax.swing.JLabel id_parteLabel;
    private javax.swing.JLabel incLabel;
    private javax.swing.JTextField incidenciaTextField;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JLabel lenguageLabel;
    private javax.swing.JComboBox lenguageSelect;
    private javax.swing.JList listaIncid;
    private javax.swing.JButton rechazarButton;
    private javax.swing.JButton salirButton;
    private javax.swing.JLabel tEstimadoLabel;
    private javax.swing.JTextField tEstimadoTextField;
    private javax.swing.JLabel tInvertidoLabel;
    private javax.swing.JTextField tInvertidoTextField;
    // End of variables declaration//GEN-END:variables
    private DefaultComboBoxModel IncidenciasBoxModel;
    private DefaultListModel listModel;
}
